﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Configuration;
using vHCS.HR.Business;
using Core.Common.Session;

namespace vHCS.K2App.Shared
{
    public class HistoryComment
    {
        public bool CheckUserInCharge(string userName, int appId, short proType)
        {
            // If is admin user
            string[] adminUser = ConfigurationManager.AppSettings["K2_Admin_User"].ToString().Split(',');
            for (int i = 0; i < adminUser.Count(); i++)
            {
                if (adminUser[i] == userName) return true;
            }

            // If normal user
            HR.Business.HR_WorkingRecordCollection col = new HR.Business.HR_WorkingRecordCollection();
            DataTable dt = col.SelectHistoryApprove(appId, proType);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["Signer"].ToString() == userName) return true;
            }

            return false;
        }

        public void InsertReviewerComment(long appId, List<string> ccUsers, short processType)
        {
            if (ccUsers.Count() < 1) return;
            HR_WorkingRecordCollection his = new HR_WorkingRecordCollection();
            foreach (var ccUser in ccUsers)
            {
                his.InsertHistory(appId, DateTime.Now, ccUser, "Reviewer", "Review", "", processType, 15);
            }
        }
    }
}